<?php
namespace app\common\model;
use think\Model;

class AdminNav extends Base
{
   protected $autoCheckFields = true;
   public  function getNavTree($where=''){

        $order['sort'] = 'desc';
        $order['create_time'] = 'asc';
        $list = $this->where($where)->order($order)->select()->toArray();
        return list_to_tree($list);
  
   }
  public function getAdminNavInfoByTitle($title){
        $where['title'] = $title;
       return   $this->where($where)->find();
   }
  public function getAdminNavInfoById($id){
     $where['id'] = $id;
     return $this->where($where)->find();
  }

   public function add($data){
   	   if(empty($data) || !is_array($data)){ 
   	    	return false;
   	    }
        return $this->data($data)->save();
    
  }
  public function edit($data,$where){
      if(empty($data) || !is_array($data)){ 
          return false;
        }
      return $this->save($data,$where);
  }
   public function updateNav($post){
        if(empty($post) || !is_array($post) ){ 
          return false;
        }

        if($this->update($post)){
            return true;
        }else{
             return false;
      }
 

  }
   public function del($id){
      if(is_array($id)){
          $idData = implode(',',$id);
      }
     $idData = $id;
     $res = $this->where("id",'in',$idData)->delete();
        if($res){
           return true;
        }else{
           return false;
        }

  }

}
